package cn.iocoder.yudao.module.fengdong.smartelderly.controller.app.billing;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.fengdong.smartelderly.controller.admin.billing.vo.*;
import cn.iocoder.yudao.module.fengdong.smartelderly.convert.billing.BillingConvert;
import cn.iocoder.yudao.module.fengdong.smartelderly.dal.dataobject.billing.BillingDO;
import cn.iocoder.yudao.module.fengdong.smartelderly.service.billing.BillingService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.Collection;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;

@Tag(name = "用户 APP - 收费记录")
@RestController
@RequestMapping("/fengdong.smartelderly/billing")
@Validated
public class AppBillingController {

    @Resource
    private BillingService billingService;

    @PostMapping("/create")
    @Operation(summary = "创建收费记录")
    public CommonResult<Long> createBilling(@Valid @RequestBody BillingCreateReqVO createReqVO) {
        return success(billingService.createBilling(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新收费记录")
    public CommonResult<Boolean> updateBilling(@Valid @RequestBody BillingUpdateReqVO updateReqVO) {
        billingService.updateBilling(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除收费记录")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteBilling(@RequestParam("id") Long id) {
        billingService.deleteBilling(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得收费记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<BillingRespVO> getBilling(@RequestParam("id") Long id) {
        BillingDO billing = billingService.getBilling(id);
        return success(BillingConvert.INSTANCE.convert(billing));
    }

    @GetMapping("/list")
    @Operation(summary = "获得收费记录列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    public CommonResult<List<BillingRespVO>> getBillingList(@RequestParam("ids") Collection<Long> ids) {
        List<BillingDO> list = billingService.getBillingList(ids);
        return success(BillingConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得收费记录分页")
    public CommonResult<PageResult<BillingRespVO>> getBillingPage(@Valid BillingPageReqVO pageVO) {
        PageResult<BillingDO> pageResult = billingService.getBillingPage(pageVO);
        return success(BillingConvert.INSTANCE.convertPage(pageResult));
    }
}
